const http=require('http')
const fs=require('fs')
const path=require('path')

http.createServer((req,res)=>{
    if(req.url=='/'){
        var filePath=path.join(__dirname,'/test.html')
        var fileContent=fs.readFileSync(filePath)
        res.writeHead(200,{'Content-Type':'text/html'})
        res.write(fileContent)
        res.end()
    }
    else if(req.url=='/getdata'){
        var arr=[
            {userName:'zhangsan',age:20},
            {userName:'lisi',age:20}
        ]
        var jsonStr=JSON.stringify(arr)
        res.writeHead(200,{'Content-Type':'text/plain'})
        res.write(jsonStr)
        res.end()
    }
    
}).listen(8083)

console.log('server is listening 8083')